<?php
defined('BASEPATH') OR exit('No direct script access allowed');

//会员动作信息
class Dongzuo extends MY_Controller {

	function __construct(){
		parent::__construct();
		
	}	

	//start
	/**
	* @name 获取会员拥有的动作
	* @param uid ture int 会员ID
	* @return 返回数组{id、name}对象
	*/
	//end
	function get_sport(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);
		
		$this->load->model('User/MemberSportModel','Sport');
		$list = $this->Sport->get_list($uid);
		
		
		$this->data_out($list);
	}
	
	//start
	/**
	* @name 获取会员动作的评估列表
	* @param uid ture int 会员ID
	* @param sid ture int 动作ID
	* @return 返回数据列表
	*/
	//end
	function get_sport_pinggu(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);
		$sid = $this->input->post('sid',null,0);
		
		$this->load->model('User/MemberSportModel','Sport');
		$this->load->model('User/MemberSportPingguModel','SportPg');
		
		$info = $this->Sport->get_info($uid,$sid);
		if(!$info){
			$this->err_out("数据错误");
		}
		
		$list = $this->SportPg->get_list($uid,$sid);
		$this->data_out($list);
	}
	//start
	/**
	* @name 添加会员动作的评估
	* @param uid ture int 会员ID
	* @param sid ture int 动作ID
	* @param position ture char 部位
	* @param info ture char 评估情况
	* @param img false char 图片链接
	* @return 返回数据列表
	*/
	//end
	function add_sport_pinggu(){
		$user_id = $this->user_id;
		
		$uid = $this->input->post('uid',null,0);
		$sid = $this->input->post('sid',null,0);
		
		$position  = trim($this->input->post('position',null,''));
		
		$arr = array(
			'info'=>$this->input->post('info',null,''),
			'img'=>$this->input->post('img',null,''),
		);
		$arr['position'] =  $position;
		$arr['sid'] =  $sid;
		$ver_arr = array(
			'position'=>"评估部位不能为空",
			'info'=>"评估情况不能为空",
			'sid'=>"所属动作不能为空",
		);
		$result = $this->CheckData($ver_arr,$arr);
		
		if($result){
			$this->err_out($result);
		}
		$this->load->model('User/MemberSportModel','Sport');
		$info = $this->Sport->get_info($uid,$sid);
		if(!$info){
			$this->err_out("数据错误");
		}
		
		
		$this->load->model('User/MemberSportPingguModel','SportPg');
		
		$row = $this->SportPg->pos_get_info($uid,$sid,$position);
		
		if($row){
			$this->SportPg->edit($arr,"id='{$row['id']}'");
		}
		else{
			
			$arr['sid'] =  $sid;
			$arr['user_id'] =  $uid;
			
			$this->SportPg->add($arr);
		}
		
		$this->data_out($arr);
	}
}
